/** 
 * 修改-新增 产权
*/
<template>
    <vp-dialog :span="1" ref="dialogRef">    
        <template #title>
            <vp-label v-if="type == 'add'" zh="新增" en="Add" align="left"/>
            <vp-label v-if="type == 'edit'" zh="修改" en="Edit" align="left"/>
        </template>
        <PropertyRights ref="commRef" :id="id" :type="type"></PropertyRights>
        <template #footer>
            <vp-btn-submit :loading="saveLoading" @click="handleSave"/>
        </template>
    </vp-dialog>
</template>

<script setup lang="ts" name="EditPropertyRights">
import { defineAsyncComponent, defineExpose, ref } from 'vue'
import request from '/@/utils/request';

const PropertyRights = defineAsyncComponent(() => import('./propertyRights.vue'));

const emits = defineEmits<{
    (e: 'formSubmited'): void
}>()

const dialogRef = ref();
const type = ref('add');
const id = ref('');
const saveLoading = ref(false);

const commRef = ref();

const handleOpen = (_type: string, _id: string)=>{
    id.value = _id;
    type.value = _type;
    dialogRef.value.handleOpen();
}

const handleSave = () =>{
    saveLoading.value = true;
    commRef.value.getData().then((data: any) =>{
        request.post("/basicData/propertyRights/" + type.value, {
            ...data,
        }).then(() => {
            emits('formSubmited')
            dialogRef.value.handleClose();
        })
        .catch(() => {})
        .finally(() => {
            saveLoading.value = false;
        });
    }).catch(()=>{saveLoading.value = false;});    
}

defineExpose({
    handleOpen
})
</script>
<style scoped lang="scss">

</style>
